package com.zeyi.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zeyi.blog.dao.DictionaryDao;
import com.zeyi.blog.entity.Dictionary;
import com.zeyi.blog.service.DictionaryService;
import com.zeyi.blog.util.TreeUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 字典表(Dictionary)表服务实现类
 *
 * @author 黎先森
 * @since 2020-07-23 08:20:52
 */
@Service("dictionaryService")
public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, Dictionary> implements DictionaryService {

    @Override
    public List<Dictionary> getAll() {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("dic_sort");
        List<Dictionary> dictionaries = this.baseMapper.selectList(queryWrapper);
        return TreeUtil.getTreeList(null, dictionaries, null);
    }

    @Override
    public List<Dictionary> getAllByGroup(String groupName) {
        List<Dictionary> dictionaries = this.baseMapper.getAllByDicGroup(groupName);
        return dictionaries.stream().filter(item -> item.getPid() != null).collect(Collectors.toList());
    }
}